home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Skunkware 5
/
Skunkware 5.iso
/
src
/
Tools
/
glimpsehttp
/
news
/
build_db
next >
Wrap
Text File
|
1995-05-16
|
2KB
|
65 lines
#!/usr/local/bin/perl
#
# Build articles database from scratch
# where your news archiving directory is
$HTTPD_NEWSHOME="/usr1/paul/news";
$gunzip="/usr/local/bin/gunzip";
$newsbin = $HTTPD_NEWSHOME;
# output file
$out = "$HTTPD_NEWSHOME/groups/articles.db";
open(OUT, ">$out.new") ||
die "Cannot create $out.new: $!";
chdir "$HTTPD_NEWSHOME/groups" ||
die "Cannot chdir to $HTTPD_NEWSHOME/groups: $!";
$groups = `awk '{print \$1}' ../getnews.cfg`;
foreach $group (split(/\n+/,$groups)) {
$group =~ s/^#\s*//;
chdir $group ||
die "Cannot chdir to $group: $!";
opendir(DIR,".") || die "Cannot open .: $!";
file: while ($file = readdir(DIR)) {
next if $file =~ /^\./;
$input = ($file =~ /\.gz/)?"exec $gunzip < $file|":"<$file";
open(INPUT,"$input") || die "Cannot open $input: $!";
$author = '';
$address = '';
$subject = '';
$ID = '';
$date = '';
$article = "/$group/$file";
while (<INPUT>) {
chop; # strip record separator
last if /^$/;
if (/^From: (.*)/) {
$author = $1;
$address = $1 if /(\w[-+.\w]+@\w[-+.\w]*)/;
}
if (/^Message-ID: <([^ ]+)>/) {
$ID = $1;
}
if (/^Subject: (.*)/) {
$subject = $1;
}
if (/^Date: (.*)/) {
$date = $1;
}
}
print OUT "$article\t$ID\t$address\t".
"$author\t$subject\t$date\n";
# $article, $ID, $address, $author, $subject, $date
close IN;
}
closedir(DIR);
chdir "..";
}
close OUT;
# force index update
open(OUT,">$HTTPD_NEWSHOME/groups/newarticles");
close OUT;
system "/bin/sort -T . $out.new >$out";
# unlink "$out.new";
exec "$newsbin/build_idx";